package co.th.bjc.md.controller.impl;

import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import co.th.bjc.md.dao.BJCDepartment;
import co.th.bjc.md.dao.CustomerData;
import co.th.bjc.md.dao.Hospital;
import co.th.bjc.md.dao.HospitalDepartment;
import co.th.bjc.md.dao.ImpRating;
import co.th.bjc.md.dao.Person;
import co.th.bjc.md.dao.Product;
import co.th.bjc.md.dao.ProductCategory;
import co.th.bjc.md.dao.RpRating;
import co.th.bjc.md.dao.SalePerson;
import co.th.bjc.md.dao.Supplier;
import co.th.bjc.md.helper.impl.CustomerDataHelper;
import co.th.bjc.md.helper.impl.ProductHelper;
import co.th.bjc.md.helper.impl.SupplierHelper;
import co.th.bjc.md.service.interfaces.CustomerDataManageService;

public class CustomerDataManageImpl implements CustomerDataManageService {

	@Override
	public List<CustomerData> getCustomerDataList(String type,
			String department, int minBed, int maxBed, int presidentImpRate,
			int presidentRpRate, int directorImpRate, int directorRpRate,
			int limitFrom, int limitTo) {
		// TODO Auto-generated method stub
		
		CustomerDataHelper cus = new CustomerDataHelper();
		List<CustomerData> cusList = null;
		try {
			cusList = cus.getListCustomerData(type, department, minBed, maxBed, presidentImpRate, presidentRpRate, directorImpRate, directorRpRate, limitFrom, limitTo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return cusList;
	}

	@Override
	public CustomerData getEditCustomerData(BigInteger id) {
		
		return null;
	}

	@Override
	public boolean removeCustomerData(BigInteger id) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean addCustomerData(CustomerData customerData) {
		// TODO Auto-generated method stub
		Connection conn = null;
		CustomerDataHelper obj = new CustomerDataHelper();
		CustomerData cus = obj.addCustomerData(conn, customerData);
		boolean result = false;
		if(cus != null){
			result = true;
		}
		return result;
	}

	@Override
	public boolean editCustomerData(CustomerData customerData) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public List<Hospital> getHostpitalList(int regionId) {
		// TODO Auto-generated method stub
		List<Hospital> list = new ArrayList<Hospital>();
		Hospital h1 = new Hospital();
		h1.setHospitalCode("001");
		h1.setHospitalName("วชิระ ภูเก็ต");
		h1.setHospitalNameEn("Vachira phuket");
		list.add(h1);
		
		Hospital h2 = new Hospital();
		h2.setHospitalCode("002");
		h2.setHospitalName("มหาราช");
		h2.setHospitalNameEn("Maharach");
		list.add(h2);
		return list;
	}

	@Override
	public List<HospitalDepartment> getDepartmentList(String hospitalCode) {
		// TODO Auto-generated method stub
		List<HospitalDepartment> list = new ArrayList<HospitalDepartment>();
		HospitalDepartment hd1 = new HospitalDepartment();
		hd1.setDepartmentId("01");
		hd1.setHospitalDepartmentName("X-Rey");
		list.add(hd1);
		HospitalDepartment hd2 = new HospitalDepartment();
		hd2.setDepartmentId("02");
		hd2.setHospitalDepartmentName("OB-GYN");
		list.add(hd2);
		return list;
	}

	@Override
	public List<BJCDepartment> getBJCDepartment() {
		// TODO Auto-generated method stub
		
//		DepartmentHelper helper = new DepartmentHelper();
//		try {
//			List<Department> list = helper.findByAll();
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		List<BJCDepartment> list = new ArrayList<BJCDepartment>();
		BJCDepartment b1 = new BJCDepartment();
		b1.setDepartmentId(1);
		b1.setDepartmentName("MIT");
		list.add(b1);
		
		BJCDepartment b2 = new BJCDepartment();
		b2.setDepartmentId(2);
		b2.setDepartmentName("Surgary");
		list.add(b2);
		return list;
	}

	@Override
	public SalePerson getSalePerson(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<ProductCategory> getProductCategoryList() {
		// TODO Auto-generated method stub
		List<ProductCategory> list = new ArrayList<ProductCategory>();
		ProductCategory p1 = new ProductCategory();
		p1.setProductCategoryId(1);
		p1.setProductCategoryName("X-Ray");
		list.add(p1);
		ProductCategory p2 = new ProductCategory();
		p2.setProductCategoryId(2);
		p2.setProductCategoryName("Ultrasound");
		list.add(p2);
		ProductCategory p3 = new ProductCategory();
		p3.setProductCategoryId(3);
		p3.setProductCategoryName("Shockwave");
		list.add(p3);
		return list;
	}

	@Override
	public List<Supplier> getSupplierList(int categoryId) {
		// TODO Auto-generated method stub
		SupplierHelper helper = new SupplierHelper();
		List<Supplier> list = null;
		try {
			list = helper.getSupplierAll();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return list;
	}

	@Override
	public List<Product> getProductList(BigDecimal supplierCode) {
		// TODO Auto-generated method stub
		ProductHelper helper = new ProductHelper();
		List<Product> listProduct = null;
		try {
			listProduct = helper.findProduct(null, supplierCode);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return listProduct;
	}

	@Override
	public CustomerData getViewCustomerData(BigInteger id) {
		// TODO Auto-generated method stub
		 CustomerDataHelper helper = new CustomerDataHelper();
		 CustomerData customerData = helper.findByCustomerDataId(id);
		
		return customerData;
	}

	@Override
	public Hospital getHospitalDepartmentDetail(String hospitalCode,
			String departmentCode) {
		// TODO Auto-generated method stub
		Hospital h = new Hospital();
		h.setEmail("hospital@hospital.com");
		h.setTelephone("02928730");
		h.setAddress("353 ถนนเยาวราช ตำบลตลาดใหญ่ อำเภอเมือง จังหวัดภูเก็ต รหัสไปรษณีย์ 83000");
		h.setHospitalType("PB");
		
		HospitalDepartment hd = new HospitalDepartment();
		hd.setBedCapMax(200);
		hd.setBedCapMin(100);
		
		Person president = new Person();
		president.setEmail("sakda@president.com");
		president.setFirstName("ศักดา");
		ImpRating presidentImp = new ImpRating();
		presidentImp.setImpCode(Integer.valueOf(3));
		president.setImpRating(presidentImp);
		president.setLastName("หาญใจ");
		president.setPersonId(BigDecimal.valueOf(Long.parseLong("1")));
		RpRating presidentRp = new RpRating();
		presidentRp.setRpCode(Integer.valueOf(5));
		president.setRpRating(presidentRp);
		president.setTelephone("0918737270");
		president.setTitle("นพ.");
		president.setPersonType(1);
		h.setPerson(president);
		
		Person director = new Person();
		director.setEmail("mana@director.com");
		director.setFirstName("มานะ");
		ImpRating directorImp = new ImpRating();
		directorImp.setImpCode(Integer.valueOf(3));
		director.setImpRating(directorImp);
		director.setLastName("ปิติยินดี");
		director.setPersonId(BigDecimal.valueOf(Long.parseLong("2")));
		RpRating directorRp = new RpRating();
		directorRp.setRpCode(Integer.valueOf(5));
		director.setRpRating(directorRp);
		director.setTelephone("0918283718");
		director.setTitle("นพ.");
		director.setPersonType(2);
		hd.setPerson(director);
		
		h.setHospitalDepartment(hd);
		
		return h;
	}

	@Override
	public InputStream getImgBlob(BigInteger id) {
		// TODO Auto-generated method stub
		CustomerDataHelper cus = new CustomerDataHelper();
		InputStream in = null;
		try {
			in = cus.getImgBlob(id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return in;
	}

	@Override
	public Integer countTotalRecord(String type,
			String department, int minBed, int maxBed, int presidentImpRate,
			int presidentRpRate, int directorImpRate, int directorRpRate) {
		// TODO Auto-generated method stub
		CustomerDataHelper cus = new CustomerDataHelper();
		int count = cus.countTotalRecords(type, department, minBed, maxBed, presidentImpRate, presidentRpRate, directorImpRate, directorRpRate);
		return count;
	}

}
